﻿using System;
using System.IO;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FineUI;
using Maticsoft.BLL;
using Maticsoft.Model;

namespace FineUI.Examples
{
    public partial class admin_updateclass : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserName"] == null)
            {
                Response.Redirect("~/login.aspx");
            }
            BindGrid();

        }

        public DataSet BindGrid()
        {
            Maticsoft.BLL.Class currentClas = new Maticsoft.BLL.Class();
            DataSet RtDate = currentClas.GetAllList();

            DataView view1 = RtDate.Tables[0].DefaultView;
            Grid1.DataSource = view1;
            Grid1.DataBind();
            return RtDate;


        }


        protected void search_btn_Click(object sender, EventArgs e)
        {
        }

        protected void ClassDelete(string current_CL_Id)
        {
            Maticsoft.BLL.Class Class = new Maticsoft.BLL.Class();
            Class.Delete(current_CL_Id);
        
        }

        protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
        {
            //删除
            if (e.CommandName == "ActionDelete")
            {
                int key=e.RowIndex;
                string current_CL_Id = BindGrid().Tables[0].Rows[key]["CL_Id"].ToString();
                ClassDelete(current_CL_Id);
                Response.Redirect("~/admin_updateclass.aspx");
            }


            //修改
            if(e.CommandName=="ActionUpdate")
            {
                int key = e.RowIndex;
                string current_CL_Id = BindGrid().Tables[0].Rows[key]["CL_Id"].ToString();
                string current_CL_Name = BindGrid().Tables[0].Rows[key]["CL_Name"].ToString();
                string current_CL_Address = BindGrid().Tables[0].Rows[key]["CL_Address"].ToString();

                Session["CL_Id"] = current_CL_Id;
               
                Session["CL_Address"] = current_CL_Address;

                ClassDelete(current_CL_Id);
                Response.Redirect("~/admin_readdclass.aspx");

            }
            





        }

        protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
        {
            Grid1.PageIndex = e.NewPageIndex;
            BindGrid();
        }

    }
}